<?php
    include("header.php");
    setTabIndex(2);
    createPage("Liga - Zilveren Toren");
?>

<?php
  	$conn = mysql_connect(DB_SERVER, DB_USER, DB_PWD);
	mysql_select_db(DB_CATALOG);

	$dep = $_GET['dep'];
    $nrOfGames = "geen";
    
    if (isset($_SESSION['user'])) $user = $_SESSION['user'];
    
	
	$query = "select max(c.round_nr) as round from zt_calendar c 
		join zt_game g on g.calendar_id = c.calendar_id
		join zt_team ht on ht.team_id = g.home_team
		join zt_team vt on vt.team_id = g.visit_team
		join zt_tournament th on th.tournament_id = ht.tournament_id
		join zt_tournament tv on tv.tournament_id = ht.tournament_id
		join zt_group hgr on hgr.group_id = ht.group_id
		join zt_group vgr on vgr.group_id = vt.group_id 
		where (hgr.group_name = '".$dep."' or vgr.group_name = '".$dep."')
		and th.iscurrent = 1 and tv.iscurrent = 1";
	$result = mysql_query($query, $conn);
	$row = mysql_fetch_assoc($result);
    $round = $row['round'];
    
    $query = "select count(1) as nrOfGames from zt_game g 
    	join zt_calendar c on g.calendar_id = c.calendar_id
		join zt_team ht on ht.team_id = g.home_team
		join zt_team vt on vt.team_id = g.visit_team
		join zt_group hgr on hgr.group_id = ht.group_id
		join zt_group vgr on vgr.group_id = vt.group_id
		join zt_tournament th on th.tournament_id = ht.tournament_id
		join zt_tournament tv on tv.tournament_id = ht.tournament_id
		where (hgr.group_name = '".$dep."' or vgr.group_name = '".$dep."')
		and th.iscurrent = 1 and tv.iscurrent = 1 and c.round_nr = ".$round;
    $result = mysql_query($query, $conn);
	if (isset($round)) {
        $row = mysql_fetch_assoc($result);
        $nrOfGames = $row['nrOfGames'];
    } else {
        $round = "1";
    }
?>

<head>
<style>
.clsTableTitle {
	font-family: Verdana, "MS Sans Serif";
	font-size: 8pt;
	font-weight: bold;
	color: #E0FFFF;
	text-align: left;
	border: 1px inset;
	background-image: url(/assets/images/bars/winbar_blue.jpg);
}
</style>
</head>

<table height="100%" cellSpacing="0" cellPadding="0" width="100%" border="0" bgcolor="#FFFFFF">
	<tr>
		<td id="leftFiller" valign="top" height="100%" rowspan="3" bgcolor="#666666">
			<table border="0" cellpadding="0" cellspacing="0" height="100%" width="8px">
				<tr><td>&nbsp;</td></tr>
			</table>
		</td>
		<td id="header" valign="top" width="100%">
			<table border="0" width="100%" cellpadding="3" cellspacing="0" bgcolor="#10425b">
                <tr>
                    <td bgcolor="#666666" width="40%">
                        <?php include("inc_title.html"); ?>
                    </td>
                    <td bgcolor="#666666" align="right" valign="top">&nbsp;
                          <span class="headerSmall">Huidige versie PLAYER.DBF: <?=CURRENT_PLAYER_DBF?>
                        <?php
                        if (isset($user) && $user->club_id == 100) {
                        ?>
                        <br/>
                        <a class="headerSmall" href="import_player.php">laad andere versie</a>
                        <?php
                        }
                        ?>
                        </span>
                    </td>
                </tr>
            </table>
            <table align="center" border="0" width="100%" height="90%" cellpadding="0" cellspacing="0" style="border-top:#BCDD10 4px solid;">
                <tr>
                    <?php include("inc_sublinks.php"); ?> 
                </tr>
				<tr><td colspan="2" nowrap bgcolor="#BCDD10" height="4"><img src="../../assets/images/spacer.gif" alt="" height="1" width="1"></td></tr>
				<tr>
					<td>&nbsp;</td>
					<td valign="top">
						<table align="left" cellspacing="10" width="100%">
							<tr>
								<td>
                  <span class="blackHeaderLarge">Zilveren Toren <?=CURRENT_ZT_YEAR?>
                  - Afdeling <?=$dep?></span>
                  <br>&nbsp;<br>
                  <?php
                  $query = "select g.group_name from zt_group g join
		          	zt_tournament zt on zt.tournament_id = g.tournament_id
		            where zt.isCurrent = 1";
		          $result = mysql_query($query, $conn);
		          while ($row = mysql_fetch_assoc($result)) {
                  	$groupName = $row['group_name'];
                  ?>
                  <a class="quicklink" href="zt_department.php?dep=<?=$groupName?>">Afdeling <?=$groupName?></a>|</li>
                  <?php
                  }
                  ?>
                  <br>&nbsp;<br>
                  <?php
                  if ($nrOfGames > 1) {
                  ?>
                  Er zijn <?=$nrOfGames?> uitslagen beschikbaar voor ronde <?=$round?>.
                  <?php	
                  } else {
                  ?>
                  Er is <?=$nrOfGames?> uitslag binnengekomen voor ronde <?=$round?>.
                  <?php
                  }
                  ?>
                  <br>&nbsp;<br>                  
                  <span class="headerMedium" style="color:#993366">A. Uitslagen</span>
                  <ul>
                  <li class="quicklink"><a href="view_crosstable.php?dep=<?=$dep?>">Stand</a></li>
                  <li class="quicklink"><a href="view_game_list.php?dep=<?=$dep?>&round=<?=$round?>">Partijen</a></li>
                  <li class="quicklink"><a href="view_player_stats.php?dep=<?=$dep?>">Statistieken spelers</a></li>
                  <li class="quicklink"><!--<a href="view_player_team_stats.php?dep=<?=$dep?>"> --><label style="color:#999999">Statistieken spelers (per ploeg) - nog niet beschikbaar</label><!-- </a> --></li>
                  </ul>
                  <?php
                  	if (isset($user) && $user->club_id == 100) {
                  ?>  
                  <span class="headerMedium" style="color:#993366">B. Administratie</span>
                  <ul>
                  <li class="quicklink"><a href="calculate_stats.php?dep=<?=$dep?>">Herbereken statistieken</a>
                  &nbsp;&nbsp;- Hier kan u manueel de stand, spelers/teamstatistieken herberekenen</li>
                  </ul>
                  <ul>
                  <li class="quicklink"><a href="view_elo_export.php?dep=<?=$dep?>">Voorbeeld ELO-bestand</a>
                  &nbsp;&nbsp;- Preview CSV-bestand om naar Daniel Halleux te sturen</li>
                  </ul>
                  <?php
                  	}
                  ?>
								</td>
							</tr>
							<tr>
								<td>
								<table align="left" width="95%" border="0"  cellspacing="0" cellpadding="2" class="small">
									<tr align="center"><td colspan="2"></td></tr>
									<th colspan="2" class="clsTableTitle">
									<strong>Overzicht</strong>
									</th>
									<tr><td><label style="color:#999999">Nog niet beschikbaar</label></td></tr>
								</table>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
			</table>
		</td>
	</tr>
</table>

<?php include("footer.php"); ?>